<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>

<div id="app">
    <div>
        {{message}}
    </div>
    <div>
        <button v-on:click="logout">登出</button>
     </div>

</div>

<script>
    var app=new Vue({
    el:'#app',
    data:{
        baseUrL:"http://localhost:8080",
        url:"/admin/hello",
        logoutUrl:"/logout",
        forwardUrl:"/html/login1.html",
        message:null
    },
    created:function() {
        axios.get(this.url)
            .then((response) => {
                if (response.data.status == 0) {
                    //失败,重定向
                    alert("没有验证");
                    window.location.href=this.forwardUrl;
                    return;
                }
                this.message = response.data.message;

            })
    },
    methods:{
        logout:function () {
            axios.post(this.logoutUrl
            ).then((response)=>{
                if(response.data.status == 1){
                    //退出成功
                    alert("退出成功")
                    window.location.href=this.forwardUrl;
                    return;
                }
                alert("退出失败")

            })
        }
    }
    })
    app.url=app.baseUrL+app.url;
    app.forwardUrl=app.baseUrL+app.forwardUrl;
    app.logoutUrl=app.baseUrL+app.logoutUrl;
</script>


</body>

</html>